﻿using CodeFinder.Bussiness.Concretes;
using Ninject;
using System;
using System.Web.Mvc;
using CodeFinder.Common.Interfaces;

namespace CodeFinder.Web.Infrastructure {
    public class NinjectControllerFactory : DefaultControllerFactory {
        private IKernel m_ninjectKernel;
        public NinjectControllerFactory() {
            m_ninjectKernel = new StandardKernel();
            AddBindings();
        }

        protected override IController GetControllerInstance(System.Web.Routing.RequestContext requestContext, Type controllerType) {
            return controllerType == null ? null : (IController)m_ninjectKernel.Get(controllerType);
        }
        private void AddBindings() {
            m_ninjectKernel.Bind<IUserService>().To<UserService>();
            m_ninjectKernel.Bind<IPostService>().To<PostService>();
        }
    }
}